﻿#pragma once
#include <string>
#include <vector>
#include <inttypes.h>
#include "hdmap/HDMap.hpp"


/**
 *  \mainpage Auto SDK HDMap Module
 *  <div style='margin:2%;'>
 *    <p>
 *      AutoSDK class is the main entrance for all feature modules. You can get pointers of all modules. Lifecycle will be maintained internally. You don't need to release explicitly. But you have to call Release() for AutoSDK at the end.
 *    	<br/>
 *      HDMap is a module of AutoSDK, which can provide efficient HD data query function.
 *    </p>
 *  </div>
 *
 *  <h2>Use example</h2>
 *  @verbatim
    
    #include "AutoSDK.hpp"
	#include "hdmap/IHDMap.hpp"

	void main()
	{
	    Navinfo::Engine::AutoSDK *p_AutoSDK = CreateAutoSDK();
	    if(!p_AutoSDK->Config(std::string("config.ini")))
	    {
	    	...
	        // error handling.
	    }
	    if(!p_AutoSDK->Start())
	    {
	    	...
	        // error handling.
	    }
	    Navinfo::Engine::IHDMap *p_hdMap = p_AutoSDK->GetHDMap();
		if (p_hdMap!= nullptr){
			Navinfo::Engine::Pos3D pt;
			pt.m_Longitude = 121.17403;
			pt.m_Latitude = 31.17403;
			double distance = 1000;
			std::vector <uint64_t> vtLanes;
			p_hdMap->SearchLanesByRadiusRange(&pt, distance, vtLanes);
			...
		}

	    p_AutoSDK->Release();
	    p_AutoSDK = nullptr;
	}
    @endverbatim
 */



/**
* @brief Navinfo namespace
*
*/
namespace Navinfo{
	/**
	* @brief Engine namespace
	*
	*/
	namespace Engine{
		/**
		* @brief Planning namespace
		*
		*/
		namespace Planning{
			struct HDRouteInfo;
		}

		
		/**
		 * @brief Interface of HDMap Module
		 */
		class IHDMap
		{
		public:
			IHDMap(){}
			virtual ~IHDMap(){}

			/**
			 *  @brief Set vehicle position information
			 *  @param oCoord vehicle position @see Navinfo::Geometry::Coordinate
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode SetLocation(const Pos3D *oCoord) = 0;

			/**
			 *  @brief Get lastest Vehicle Coordnate value for SetLocation changed
			 *  @param oCoord vehicle position @see Navinfo::Geometry::Coordinate
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetLocation(Pos3D *oCoord) = 0;

			/**
			 *  @brief Match the nearest road based on given vehicle position
			 *  @param oCoord specified location @see Navinfo::Geometry::Coordinate
			 *  @param[out] nID road id 
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetMatchingRoad(const Pos3D *oCoord, uint64_t& nID) = 0;

			/**
			 *  @brief Match the nearest lane based on given vehicle position
			 *  @param oCoord specified location @see Navinfo::Geometry::Coordinate
			 *  @param[out] nID lane id
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetMatchingLane(const Pos3D *oCoord, uint64_t& nID) = 0;

			/**
			 *  @brief Search all the included roads by setting vehicle position as center point, and radius buffer
			 *  @param oCoord Search coordinate @see Navinfo::Geometry::Coordinate
			 *  @param dDistance Search range Unit: Meter
			 *  @param[out] vtRoads Search result
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 *  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when parameter greater than maximum limit
			 */
			virtual Navinfo::Common::ReturnCode SearchRoadsByRadiusRange(const Pos3D * oCoord, const double dDistance, std::vector<uint64_t>& vtRoads) = 0;

			/**
			 *  @brief Search all the included lanes by setting vehicle position as center point, and radius buffer
			 *  @param oCoord Search coordinate @see Navinfo::Geometry::Coordinate
			 *  @param dDistance Search range Unit: Meter
			 *  @param[out] vtLanes Search result
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 *  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when parameter greater than maximum limit
			 */
			virtual Navinfo::Common::ReturnCode SearchLanesByRadiusRange(const Pos3D * oCoord, const double dDistance, std::vector<uint64_t>& vtLanes) = 0;

			/**
			 *  @brief Search all the included objects by setting vehicle position as center point, and radius buffer
			 *  @param oCoord Search coordinate @see Navinfo::Geometry::Coordinate
			 *  @param dDistance Search range Unit: Meter
			 *  @param eType Search object type @see ENObjectType
			 *  @param[out] vtObjects Search result
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 *  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when parameter greater than maximum limit
			 */
			virtual Navinfo::Common::ReturnCode SearchObjectsByRadiusRange(const Pos3D * oCoord, const double dDistance, Navinfo::Common::ENObjectType eType, std::vector<uint64_t>& vtObjects) = 0;

			/**
			 *  @brief Search all the included road boundary groups by setting vehicle position as center point, and radius buffer
			 *  @param oCoord Search coordinate @see Navinfo::Geometry::Coordinate
			 *  @param dDistance Search range Unit: Meter
			 *  @param[out] vtRoadBoundaryGroups Search result
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 *  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when parameter greater than maximum limit
			 */
			virtual Navinfo::Common::ReturnCode SearchRoadBoundaryGroupsByRadiusRange(const Pos3D * oCoord, const double dDistance, std::vector<uint64_t>& vtRoadBoundaryGroups) = 0;

			/**
			 *  @brief Search all the included lane boundary groups by setting vehicle position as center point, and radius buffer
			 *  @param oCoord Search coordinate @see Navinfo::Geometry::Coordinate
			 *  @param dDistance Search range Unit: Meter
			 *  @param[out] vtLaneBoundaryGroups Search result
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 *  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when parameter greater than maximum limit
			 */
			virtual Navinfo::Common::ReturnCode SearchLaneBoundaryGroupsByRadiusRange(const Pos3D * oCoord, const double dDistance, std::vector<uint64_t>& vtLaneBoundaryGroups) = 0;

			/**
			*  @brief Search all the included roads by setting rectangle range
			*  @param oRect (minX, minY, maxX, maxY) @see Navinfo::Geometry::Rect
			*  @param[out] vtRoads Search result
			*  @return status flag @see Navinfo::Common::ReturnCode
			*  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when The diagonal length of the rectangle reater than maximum limit
			*/
			virtual Navinfo::Common::ReturnCode SearchRoadsByRect(const PosRectangle& oRect, std::vector<uint64_t>& vtRoads) = 0;

			/**
			*  @brief Search all the included lanes by setting rectangle range
			*  @param oRect (minX, minY, maxX, maxY) @see Navinfo::Geometry::Rect
			*  @param[out] vtLanes Search result
			*  @return status flag @see Navinfo::Common::ReturnCode
			*  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when The diagonal length of the rectangle reater than maximum limit
			*/
			virtual Navinfo::Common::ReturnCode SearchLanesByRect(const PosRectangle& oRect, std::vector<uint64_t>& vtLanes) = 0;

			/**
			*  @brief Search all the included objects by setting rectangle range
			*  @param oRect (minX, minY, maxX, maxY) @see Navinfo::Geometry::Rect
			*  @param eType Search object tyoe @see ENObjectType
			*  @param[out] vtObjects Search result
			*  @return status flag @see Navinfo::Common::ReturnCode
			*  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when The diagonal length of the rectangle reater than maximum limit
			*/
			virtual Navinfo::Common::ReturnCode SearchObjectsByRect(const PosRectangle& oRect, Navinfo::Common::ENObjectType eType, std::vector<uint64_t>& vtObjects) = 0;

			/**
			*  @brief Search all the included road boundary groups by setting rectangle range
			*  @param oRect (minX, minY, maxX, maxY) @see Navinfo::Geometry::Rect
			*  @param[out] vtRoadBoundaryGroups Search result
			*  @return status flag @see Navinfo::Common::ReturnCode
			*  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when The diagonal length of the rectangle reater than maximum limit
			*/
			virtual Navinfo::Common::ReturnCode SearchRoadBoundaryGroupsByRect(const PosRectangle& oRect, std::vector<uint64_t>& vtRoadBoundaryGroups) = 0;

			/**
			*  @brief Search all the included lane boundary groups by setting rectangle range
			*  @param oRect (minX, minY, maxX, maxY) @see Navinfo::Geometry::Rect
			*  @param[out] vtLaneBoundaryGroups Search result
			*  @return status flag @see Navinfo::Common::ReturnCode
			*  @note The maximum search distance is 50 km (500000). The function returns Code_Fail when The diagonal length of the rectangle reater than maximum limit
			*/
			virtual Navinfo::Common::ReturnCode SearchLaneBoundaryGroupsByRect(const PosRectangle& oRect, std::vector<uint64_t>& vtLaneBoundaryGroups) = 0;

			/**
			 *  @brief Retrieve detailed information for road feature
			 *  @param nID road ID
			 *	@param[out] oRoad Query result @see Navinfo::HDMap::Road
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetRoadByID(const uint64_t nID, Navinfo::HDMap::Road& oRoad) = 0;

			/**
			 *  @brief Retrieve detailed information for lane group feature
			 *  @brief Query LaneGroup by ID
			 *  @param nID LaneGroup ID
			 *  @param [out] oLaneGroup Query Result @see Navinfo::HDMap::LaneGroup
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetLaneGroupByID(const uint64_t nID, Navinfo::HDMap::LaneGroup &oLaneGroup) = 0;

			/**
			 *  @brief Retrieve detailed information for lane feature
			 *  @param nID lane ID
			 *	@param[out] oLane Query result @see Navinfo::HDMap::Lane
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetLaneByID(const uint64_t nID, Navinfo::HDMap::Lane& oLane) = 0;

			/**
			 *  @brief Retrieve detailed information for object feature
			 *  @param nID object ID
			 *  @param eType Query object type @see ENObjectType
			 *	@param[out] oObject Query result @see Navinfo::HDMap::Object
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetObjectByID(const uint64_t nID, Navinfo::Common::ENObjectType eType, Navinfo::HDMap::Object& oObject) = 0;

			/**
			 *  @brief Retrieve detailed information for lane boundart group feature
			 *  @param nID LaneBoundaryGroup ID
			 *	@param[out] oLaneBoundaryGroup Query result @see Navinfo::HDMap::LaneBoundaryGroup
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetLaneBoundaryGroupByID(const uint64_t nID, Navinfo::HDMap::LaneBoundaryGroup& oLaneBoundaryGroup) = 0;

			/**
			 *  @brief Search the associated localization objects by road feature id
			 *  @param nID road ID
			 *  @param eType Query object type @see ENObjectType
			 *  @param[out] vtObjects query result
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetObjectsByRoadID(const uint64_t nID, Navinfo::Common::ENObjectType eType, std::vector<uint64_t>& vtObjects) = 0;

			/**
			 *  @brief Get MataData of HDMap
			 *  @param[out] oMetadata query result
			 *  @return status flag @see Navinfo::Common::ReturnCode
			 */
			virtual Navinfo::Common::ReturnCode GetMetadata(Navinfo::HDMap::MetaData& oMetadata) = 0;

			/**
			*  @brief upload SensorData to server
			*  @param [in] pData data address
			*  @param [in] dataSize data size
			*  @param [out] state_code state code
			*  @return status flag @see Navinfo::Common::ReturnCode
			*/

			virtual Navinfo::Common::ReturnCode UploadSensorData(char* pData, size_t dataSize, int& state_code) = 0;
		};
	}
}